package com.ruyuan.eshop.seller.controller.seller.trade;

import com.ruyuan.eshop.framework.context.user.UserContext;
import com.ruyuan.eshop.framework.context.user.model.Seller;
import com.ruyuan.eshop.framework.core.WebPage;
import com.ruyuan.eshop.common.domain.entity.OrderComplainDO;
import com.ruyuan.eshop.common.domain.request.ComplainQueryParam;
import com.ruyuan.eshop.common.domain.vo.OrderComplainDOVO;
import com.ruyuan.eshop.common.domain.vo.OrderFlowNode;
import com.ruyuan.eshop.common.service.trade.OrderComplainService;
import com.ruyuan.eshop.seller.domain.request.ComplainSellerAuthRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 交易投诉表控制器
 * @author pwd
 * @version 1.0
 */
@RestController
@RequestMapping("/api/trade/order-complains")
@Api(description = "交易投诉表相关API")
public class OrderComplainSellerController {

    @Autowired
    private OrderComplainService orderComplainService;

    @ApiOperation(value = "查询交易投诉表列表")
    @GetMapping
    public WebPage list(Long pageNo, Long pageSize, ComplainQueryParam param) {
        param.setPageNo(pageNo);
        param.setPageSize(pageSize);
        Seller seller = UserContext.getSeller();
        param.setSellerId(seller.getSellerId());
        return this.orderComplainService.list(param);
    }

    @ApiOperation(value = "商家申诉")
    @PutMapping(value = "/{id}/appeal")
    public OrderComplainDO auth(@PathVariable Long id, @RequestBody ComplainSellerAuthRequest complainSellerAuthRequest) {
        return this.orderComplainService.appeal(id, complainSellerAuthRequest.getAppealContent(), complainSellerAuthRequest.getImages());
    }

    @ApiOperation(value = "查询一个交易投诉")
    @GetMapping(value = "/{id}")
    public OrderComplainDOVO get(@PathVariable Long id) {

        OrderComplainDOVO orderComplain = this.orderComplainService.getModelAndCommunication(id);

        return orderComplain;
    }

    @ApiOperation(value = "查询一个交易投诉的流程图")
    @GetMapping(value = "/{id}/flow")
    public List<OrderFlowNode> getFlow(@PathVariable Long id) {

        return this.orderComplainService.getComplainFlow(id);
    }



}
